﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ThreeByte.ActiveDeck.Data.UserResponse.Report {
    public class UserDataReport {

        protected static readonly XNamespace ns = Service.ServiceConfiguration.NAMESPACE;

        public string Presentation {
            get;
            private set;
        }

        public UserDataReport(string presentation) {
            Presentation = presentation;
            ResponseDataElements = new List<IndividualResponseData>();
        }

        public List<IndividualResponseData> ResponseDataElements {
            get;
            private set;
        }

        public XElement ToXml() {
            XElement node = new XElement(ns + "UserDataReport", new XAttribute("Presentation", Presentation));

            foreach(IndividualResponseData ird in ResponseDataElements) {
                node.Add(ird.ToXml());
            }

            return node;
        }

        public static UserDataReport ParseXml(XElement node) {
            UserDataReport userDataReport = new UserDataReport(node.Attribute("Presentation").Value);
            foreach(XElement u in node.Elements(ns + "User")) {
                userDataReport.ResponseDataElements.Add(IndividualResponseData.ParseXml(u));
            }

            return userDataReport;
        }
    }
}
